﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.StationVMs
{
    public partial class StationListVM : BasePagedListVM<Station_View, StationSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Station_View>> InitGridHeader()
        {
            return new List<GridColumn<Station_View>>{
                
                this.MakeGridHeader(x => x.Station_LineCode).SetTitle(@Localizer["Page.产线信息"].Value),
                this.MakeGridHeader(x => x.Station_StationCode).SetTitle(@Localizer["Page.工位编码"].Value),
                this.MakeGridHeader(x => x.Station_StationName).SetTitle(@Localizer["Page.工位名称"].Value),
                this.MakeGridHeader(x => x.Station_Base_Status).SetTitle(@Localizer["Page.工位状态"].Value),
                this.MakeGridHeader(x => x.Station_StationManagerID).SetTitle(@Localizer["Page.工位负责人"].Value),
                this.MakeGridHeader(x => x.Station_StationManagerName).SetTitle(@Localizer["Page.负责人姓名"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Station_View> GetSearchQuery()
        {
            var query = DC.Set<Station>()
                
                .CheckContain(Searcher.SelectedLineCodeIds, x=>x.LineCodeId)
                .CheckContain(Searcher.StationCode, x=>x.StationCode)
                .CheckContain(Searcher.StationName, x=>x.StationName)
                .CheckContain(Searcher.Base_Status, x=>x.Base_Status)
                .CheckContain(Searcher.StationManagerID, x=>x.StationManagerID)
                .CheckContain(Searcher.StationManagerName, x=>x.StationManagerName)
                .Select(x => new Station_View
                {
				    ID = x.ID,
                    
                    Station_LineCode = DC.Set<Line>().Where(z0 => z0.LineCode == x.LineCodeId).Select(y => y.LineCode).FirstOrDefault(),
                    Station_StationCode = x.StationCode,
                    Station_StationName = x.StationName,
                    Station_Base_Status = x.Base_Status,
                    Station_StationManagerID = x.StationManagerID,
                    Station_StationManagerName = x.StationManagerName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Station_View: Station
    {
        
        public string Station_LineCode { get; set; }
        public string Station_StationCode { get; set; }
        public string Station_StationName { get; set; }
        public BaseStatusEnum? Station_Base_Status { get; set; }
        public string Station_StationManagerID { get; set; }
        public string Station_StationManagerName { get; set; }

    }

}